
var http = require('http')
require('./updateApi_isrc.js')

requestData = function(updateApi,hostname,path)
{
    var options = { 
        hostname:hostname, 
        port: 80, 
        path: path, 
        method: 'GET',  
    }

    var postData = ""
    var isTimeOut = false
    var req = http.request(options, 
    function(res) 
    {  
        res.setEncoding('utf8')
        res.on('data', function(data) {
            console.log(data)
            postData += data
            })
        res.on('end', function() {            
            updateApi(postData)
            console.log('end')
            })
    });

    req.setTimeout(60000, 
    function()
    {
        console.log('timeout')
        isTimeOut = true
    })

    req.on('response', 
    function()
    {
        console.log('response',isTimeOut)
        isTimeOut?req.res.destroy():''
    })

    req.on('close', 
    function()
    {
        console.log('close')
    })

    req.end()
}

requestData(updateApi_isrc,hostname_isrc,path_isrc)


var interval = setInterval( 
            function() {

                requestData(updateApi_isrc,hostname_isrc,path_isrc)


               }, 200000)




